package com.auth.controller;

import com.auth.model.BsRolePermission;
import com.auth.service.BsRolePermissionService;
import com.exception.bean.Result;
import com.exception.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/8/22 0022.角色权限控制层
 */
@RestController
public class BsRolePermissionController {
    @Autowired
    private BsRolePermissionService bsRolePermissionService;

    /**
     * 保存角色权限
     * @param roleId 角色ID
     * @param type 权限类型（0-菜单 1-功能项）
     * @param menuId
     * @param itemId 功能ID
     * @return
     * @throws Exception
     */
    @PostMapping("role-permission/save")
    public Result bsRolePermissionSave(String roleId,int type,String menuId,String itemId,String unitiId) throws Exception{
        return bsRolePermissionService.createBsRolePermission(roleId,type,menuId,itemId,unitiId);
    }

    /**
     * 修改角色权限
     * @param bsRolePermission 角色权限
     * @return
     * @throws Exception
     */
    @PostMapping("role-permission/update")
    public  Result bsRolePermissionUpdate(BsRolePermission bsRolePermission)throws Exception{
        return bsRolePermissionService.updateBsRolePermission(bsRolePermission);
    }

    /**
     * 角色权限列表
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/role-permission/find-all-page")
    public Result findAllPage(int pageNum,int pageSize)throws Exception{
        return ResultUtil.success(bsRolePermissionService.findAllPage(pageNum,pageSize));
    }

    /**
     * 删除角色权限
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/role-permission")
    public Result deleteBsRolePermission(String id) throws Exception{
        return bsRolePermissionService.deleteBsRolePermission(id);
    }
}
